#include "map.h"
map::map()
{
    this->x=0;
    this->y=0;
    values = NULL;
}

map::~map()
{
    this->x=0;
    this->y=0;
    for(int i=0; i<x; i++)
    {

        delete values[i];

    }
    delete	values;

}

map::map(int xx)
{
    this->x = xx;
    this->y = xx;
    values = new char*[x];
    for(int i=0; i<x; i++)
    {

        values[i]=new char[y*2+1];

    }
    for(int i=0; i<x; i++)
    {
        for(int j=0; j<y*2+1; j++)
        {
            if(j%2==0)
            {
                values[i][j]='|';
            }
            else
            {
                values[i][j]='-';
            }
        }
    }
}
int map::setvalue(char value,int xpos,int ypos)
{
    if(xpos<=0||xpos > x)
    {
        cout<<"value "<<xpos <<" invalid"<<endl;
        return -1;
    }
    else if(ypos<=0||ypos > x)
    {
        cout<<"value "<<ypos<<" invalid"<<endl;
        return -2;
    }
    else
    {
        values[xpos-1][2*ypos-1] = value;
        return 1;
    }
}
void map::draw()
{
    cout<<"Map:"<<endl<<"\t";
    for(int a=0; a<2*y+1; a++)
    {
        if(a%2 !=0)
            cout<<a/2+1;
        else if(a==0)
            //cai dau tien 3 khoang tang
            cout<<"   ";
        else
            //5 khoang trang
            cout<<"     ";
    }
    cout<<endl;
    for(int i=0; i<x; i++)
    {
        cout<<"\t";
        for(int j=0; j<6*y+1; j++)
        {
            cout<<"-";
        }

        cout<<endl;
        cout<<i+1<<"\t";
        for(int j=0; j<2*y+1; j++)
        {
            cout<<values[i][j]<<"  ";
        }
        cout<<endl;

    }
    cout<<"\t";
    for(int j=0; j<6*y+1; j++)
    {
        cout<<"-";
    }
    cout<<endl;

}
char map::getvalue(int xx,int yy)
{
    return values[xx-1][yy*2-1];
}

